package com.tal.bcc.pad.cloud;

import com.tal.bcc.pad.cloud.entity.CloudUploadEntity;
import com.tal.bcc.pad.cloud.listener.CloudTaskListener;
import com.tal.bcc.pad.cloud.thread.CloudQueue;


import com.tal.bcc.pad.cloud.entity.CloudUploadEntity;
import com.tal.bcc.pad.cloud.listener.CloudTaskListener;
import com.tal.bcc.pad.cloud.listener.StsUploadListener;
import com.tal.bcc.pad.cloud.thread.CloudQueue;
import com.tal.bcc.pad.cloud.thread.CloudUpload;
import java.util.ArrayList;
import java.util.List;

public class CloudUploadBusiness {
    private CloudQueue cloudQueue = new CloudQueue();
    CloudTaskListener taskListener = new CloudTaskListener() {
        public void onReady() {
        }

        public void onComplete() {
            CloudUploadBusiness.this.cloudQueue.deQueue();
            CloudUploadBusiness.this.cloudQueueExecute();
        }

        public void onStart() {
        }
    };

    public CloudUploadBusiness() {

    }

    public CloudUpload asyncUpload(List<CloudUploadEntity> files, StsUploadListener uploadListener) {
        CloudUpload task1 = new CloudUpload( files, uploadListener, this.taskListener);
        this.cloudQueue.putQueue(task1);
        this.cloudQueueExecute();
        return task1;
    }

    public CloudUpload asyncUpload(CloudUploadEntity file, StsUploadListener uploadListener) {
        ArrayList<CloudUploadEntity> files = new ArrayList();
        files.add(file);
        return this.asyncUpload((List)files, uploadListener);
    }

    private void cloudQueueExecute() {
        if (this.cloudQueue.QueueLength() > 0) {
            CloudUpload task = this.cloudQueue.queuePeek();
            if (task.getTaskStatus() == 1) {
                task.asyncUpload();
            } else if (task.getTaskStatus() == 3) {
                this.cloudQueue.deQueue();
                this.cloudQueueExecute();
            }
        }

    }
}
